package com.agile.leetcode.listandarrayconvert;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/7/6 11:43
 */
public class ListUtil {
    public static void main(String[] args) {
        System.out.println(fillList());
        fillListArray();
    }
    // 初始化list为5个1
    public static List<Integer> fillList(){
        List<Integer> list = Collections.nCopies(5, 1);
        return list;
    }
    // 初始化arr为5个1
    public static int[] fillArr() {
        int[] arr = new int[5];
        Arrays.fill(arr, 1);
        return arr;
    }
    public static List[] fillListArray(){
        List[] lists=new List[5];
        IntStream.rangeClosed(0, 4).boxed()
                .forEach(i->lists[i] = new ArrayList());
        System.out.println(Arrays.asList(lists));
        return lists;
    }
}
